{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">采集管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
        </div>
    </div>
</div>
<script type="text/html" id="caijiTool">
    <a class="layui-btn layui-btn-xs layui-btn-normal layui-iframe" href="{:url('col_url_list')}?id={{ d.id }}" lay-data="{width:'800px',height:'400px',title:'正在采集'}">①&nbsp;采集内容</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" href="{:url('publist')}?id={{ d.id }}&type=1">②&nbsp;内容发布</a>
</script>
<button type="button" class="layui-btn layui-btn-sm" id="importFile" value="离线安装" style="display: none"/>
{/block}
{block name="script"}
<script>
layui.use(['yznTable', 'upload'], function() {
    var yznTable = layui.yznTable,
        $ = layui.$,
        upload = layui.upload;
        
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTable',
        edit_url: "{:url('edit')}",
        delete_url: "{:url('del')}",
        export_url:"{:url('export')}",
    };
    yznTable.render({
        init: init,
        toolbar: ['refresh', [{
            text: '添加',
            url: "{:url('add')}",
            method: 'open',
            class: 'layui-btn layui-btn-sm layui-btn-normal',
            icon: 'iconfont icon-add',
            extend: 'data-width="950" data-height="600"',
        }], 'delete',[{
               html:'<a class="layui-btn layui-btn-sm" onclick="importFile();"><i class="iconfont icon-upload-fill"></i>&nbsp;导入</a>'
            }]],
        url: '{:url("index")}',
        cols: [
            [
                { type: 'checkbox', fixed: 'left' },
                { field: 'name',align: "left", title: '名称' },
                { field: 'lastdate', width: 180, title: '最后采集时间', templet: '<div>{{#  if(d.lastdate){ }} {{d.lastdate}} {{#  } else { }} / {{#  } }}</div>', search: 'range' },
                { width: 200, title: '内容操作',  templet: '#caijiTool'},
                { width:130, title: '操作',templet: yznTable.formatter.tool,operat: [
                [{
                    text: '导出',
                    url: init.export_url,
                    method: 'href',
                    class: 'layui-btn layui-btn-xs layui-btn-warm',
                    extend: 'target="_blank"',
                }],'edit','delete']}
            ]
        ],
        page: {}
    });

    importFile=function (){
        $('#importFile').click();
    }

    //执行实例
    var uploadInst = upload.render({
        elem: '#importFile',
        url: '{:url("import")}',
        accept: 'file',
        exts: 'txt',
        done: function(res) {
            //上传完毕回调
            layer.alert(res.msg, {}, function(index) {
                if (res.code != 0) {
                    location.reload();
                }else{
                    layer.close(index);
                }
            });
        },
        error: function() {
            //请求异常回调
        }
    });
});
</script>
{/block}